package com.guo.hui.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.guo.hui.model.NoteBook;
import com.guo.hui.service.NoteBookServiceImpl;

import java.util.List;

/**
 * @ClassName NoteController
 * @Description TODO
 * @Author zhengguohui
 * @Date 2018/6/26 10:36
 */
@Controller
public class NoteController {

	private Logger logger = LoggerFactory.getLogger(this.getClass());

	@Autowired
	private NoteBookServiceImpl noteBookService;

	@RequestMapping("/note")
	public String note() {
		logger.info("测试:info-" + "hellonote");
		logger.error("测试:error-" + "hellonote");
		return "hello";
	}

	@RequestMapping("/notelist")
	public String list() {
		logger.info("测试:" + "notelist");
		logger.error("测试:error-" + "notelist");
		return "notelist";
	}

	@RequestMapping("/update")
	public String update(Model mm, String id) {
		NoteBook nb = noteBookService.getNote(id);
		mm.addAttribute("nb", nb);
		return "update";
	}

	@ResponseBody
	@RequestMapping("/updatesave")
	public String updatesave(String note) {
		noteBookService.updatesave(note);
		return "ok";
	}

	@ResponseBody
	@RequestMapping("/save")
	public String save(String note) {
		noteBookService.save(note);
		return "ok";
	}

	@ResponseBody
	@RequestMapping("/notedata")
	public String notedata() {
		List<NoteBook> list = noteBookService.getNoteData();
		return JSONObject.toJSONString(list);
	}

	@ResponseBody
	@RequestMapping("hello")
	public String hello() {
		return "hello";
	}
}
